#include<bits/stdc++.h>
using namespace std;

int main() {
    int N;
    cin >> N;
    list<int> q;
    unordered_map<int, list<int>::iterator> pos;
    for (int i = 0; i < N; ++i) {
        int x;
        cin >> x;
        q.push_back(x);
    }
    auto it = q.begin();
    while (it != q.end()) {
        pos[*it] = it;
        ++it;
    }
    int P;
    cin >> P;
    for (int i = 0; i < P; ++i) {
        string op;
        int x;
        cin >> op >> x;
        if (op == "FIRST") {
            auto position = pos[x];
            q.erase(position);
            q.push_front(x);
            pos[x] = q.begin();
        }
        else if (op == "LAST") {
            auto position = pos[x];
            q.erase(position);
            q.push_back(x);
            pos[x] = --q.end();
        }
    }
    for (int x : q) {
        cout << x << " ";
    }
    cout << endl;
    return 0;
}
